<template>
  <div>
    <div class="list">
      <div class="list-item" v-for="item in list" :key="item.id">
        <div class="left">
          <input
            :checked="item.isDone"
            type="radio"
            @click="changeHandler(item.id)"
          />
          <div class="text" :class="{ done: item.isDone }">{{ item.name }}</div>
        </div>
        <div class="right">
          <a href="#" @click.prevent="remove(item.id)">删除</a>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    list: {
      required: true,
      type: Array,
      default: () => [],
    },
  },
  methods: {
    // 修改勾选状态
    changeHandler(id) {
      this.$emit("change", id);
    },
    // 删除
    remove(id) {
      // 子传父
      this.$emit("remove", id);
    },
  },
};
</script>

<style lang='less' scoped>
.list {
  box-shadow: 0 0 5px #ccc;
  .list-item {
    height: 50px;
    padding: 5px;
    box-sizing: border-box;
    display: flex;
    justify-content: space-between;
    border-bottom: #ccc 1px solid;
    &:last-child {
      border: none;
    }
    .left {
      display: flex;
      align-items: center;
      font-size: 18px;
      .text {
        margin-left: 10px;
      }
    }
    .right {
      display: flex;
      align-items: center;
    }
  }
}
.done {
  color: gray;
  text-decoration: line-through;
}
</style>